Skip to content

Conversation

@geksiong
Copy link
Contributor

@geksiong geksiong commented Apr 28, 2020

This is my attempt to make bash-git-prompt work with zsh, by modifying the bash scripts without introducing additional scripts. It assumes the zsh colors module is loaded.

Disclaimer: I'm new to zsh scripting as I recently switched to zsh. It seems to work fine on my system so far, but may need more testing.

ps. It still works with bash

@MPLew-is
Copy link
Contributor

MPLew-is commented May 14, 2020

I'm also very new to zsh, but couldn't seem to get this to work; am I doing something incorrectly? Here's the excerpt from my ~/.zshrc:

autoload -U colors && colors
  
if [ -f "${HOME}/Projects/bash-git-prompt/gitprompt.sh" ]; then
    __GIT_PROMPT_DIR="${HOME}/Projects/bash-git-prompt"
    source "${HOME}/Projects/bash-git-prompt/gitprompt.sh"
fi

where ${HOME}/Projects/bash-git-prompt is where I have your zsh-support branch checked out.

@geksiong
Copy link
Contributor Author

Because bash-git-prompt sets $PROMPT_COMMAND which is specific to bash only, you need to add the following to get the prompt to take effect in zsh:
precmd() { eval $PROMPT_COMMAND}

@MPLew-is
Copy link
Contributor

Thanks, I was able to get it displaying, and have submitted a pull request into your fork to correct a few issues I found. In addition, one remaining issue that I'm seeing is that my prompt doesn't expand ${GIT_BRANCH}:

~/Projects/bash-git-prompt [${GIT_BRANCH}|✔] 

The root cause of this is the escaped \${GIT_BRANCH} in gitprompt.sh, and
going through git blame it looks like this was introduced as a security fix. Removing the indirection (that is, changing \${GIT_BRANCH} to just ${GIT_BRANCH}) fixes the issue, but I do not know enough about the security issue that that fix was designed to prevent to know if that's a good fix.

@MPLew-is
Copy link
Contributor

@magicmonty or @ogr3 do you know if it's safe to just leave ${GIT_BRANCH} unescaped on zsh? It looks like at least one level of evaluation is removed using the different shell, which might eliminate that issue entirely.

MPLew-is and others added 2 commits May 18, 2020 16:56
- Use added `NewLine` variable for zsh-specific newline
- `Time12a` variant added for zsh
Correct issues with default theme on zsh
@andruten
Copy link

I'm also interested in this feature! I've checked out your branch and works like a charm adding @MPLew-is snippet and precmd function at the end of .zshrc. It works like a charm! Thank you!

@sandrotosi
Copy link

what's the purpose of this PR? i think this project is a port for bash of https://github.com/olivierverdier/zsh-git-prompt , which provides support for customizing the zsh prompt for git. can you use that instead?

@guenhter
Copy link
Collaborator

@geksiong Could you please rebase to the latest master and ensure again, that bash is unaffected?

@MPLew-is MPLew-is mentioned this pull request Feb 21, 2023
@MPLew-is
Copy link
Contributor

@guenhter I haven't heard from geksiong in a few years (see geksiong#2), so I've put up a new PR in #525 that is rebased against the current master, along with a few of my own changes to correct some bugs in this original PR.

@guenhter
Copy link
Collaborator

Implemented via #525

@guenhter guenhter closed this Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants